package com.wyzz.hr.action;

import java.util.List;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.bo.RoleBo;
import com.wyzz.hr.bo.UserBo;
import com.wyzz.hr.pojo.Role;
import com.wyzz.hr.pojo.Userinfo;
import com.wyzz.hr.spring.SpringBeanFactory;

public class PasswordAction extends BaseAction {

	public PasswordAction() {
	}

	public String own() throws Exception {
		String no = getCurrentEmpNo();
		UserBo userService = (UserBo) SpringBeanFactory.getBean("userService");
		Userinfo userTemp = userService.getUserById(no);
		List userRoleList = userTemp.getUiRoleList();
		int len = userRoleList.size();
		RoleBo roleService = (RoleBo) SpringBeanFactory.getBean("roleService");
		List roleList = roleService.getRoleList();
		int roleListLen = roleList.size();
		String userRoleInfo = "";
		label0: for (int j = 0; j < len; j++) {
			int i = 0;
			do {
				if (i >= roleListLen)
					continue label0;
				Role tempRole = (Role) roleList.get(i);
				if (tempRole.getRoleNo() == Integer
						.parseInt((String) (String) userRoleList.get(j))) {
					if (j == 0) {
						userRoleInfo = (new StringBuilder()).append(
								userRoleInfo).append(tempRole.getRoleName())
								.toString();
						continue label0;
					}
					if (i % 5 == 0)
						userRoleInfo = (new StringBuilder()).append(
								userRoleInfo).append("<br>").append(
								tempRole.getRoleName()).toString();
					else
						userRoleInfo = (new StringBuilder()).append(
								userRoleInfo).append(" | ").append(
								tempRole.getRoleName()).toString();
					continue label0;
				}
				i++;
			} while (true);
		}

		setRoleInfo(userRoleInfo);
		setOwnPass("OWN");
		return "success";
	}

	public String getOwnPass() {
		return ownPass;
	}

	public void setOwnPass(String ownPass) {
		this.ownPass = ownPass;
	}

	public String getRoleInfo() {
		return roleInfo;
	}

	public void setRoleInfo(String roleInfo) {
		this.roleInfo = roleInfo;
	}

	private static final long serialVersionUID = 1L;
	private String ownPass;
	private String roleInfo;
}
